package com.sm.auth.controller;

import com.sm.auth.dto.LoginDto;
import com.sm.auth.service.AuthService;
import com.sm.common.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("auth")

public class AuthController {
    @Autowired
    private AuthService authService;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @PostMapping("sys")
    public Result login(@RequestBody LoginDto loginDto) {
        System.out.println(loginDto.getUsername());
        System.out.println(loginDto.getPassword());
        String token = "";
        try{
            token = authService.login(loginDto);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
        /*
            {
                msg:"操作成功"
                code:200
            }
            {
                msg:"操作成功"
                code:200
                data:asdasda-asdasd-asdad
            }
         */
        return Result.success().put("data", token);
    }

    @GetMapping("test")
    public Result test() {
        //$2a$10$LNvN7zBxW1DwdN58FeeISu49Fx43ROYue9Ehm5nyr3ZeKKGODPDqq
        String passwordSecret = passwordEncoder.encode("123456");
        System.out.println(passwordSecret);
        return Result.success();
    }
}
